﻿package plugin.roleN.handler
{
    import cmd.*;
    import com.core.*;
    import consts.*;
    import flash.utils.*;
    import manager.*;
    import plugin.newvip.model.*;
    import plugin.roleN.model.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;
    import view.*;

    public class RoleNHandler extends Object implements IGroupHandler
    {
        private var input:Input;
        private var _lastfix:int = 0;

        public function RoleNHandler()
        {
            this.input = new Input(null);
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_9:String = null;
            var _loc_10:int = 0;
            switch(param1.getCmd())
            {
                case CMDRole.PutOn:
                {
                    _loc_5 = param1.getParam();
                    _loc_3 = ModelProxy.getValue("data", "arms");
                    _loc_3[_loc_5.pos] = _loc_5.data;
                    ModelProxy.change("role", "onarm", param1.getParam());
                    ModelProxy.change("wing", "loadEquip", param1.getParam());
                    ModelProxy.change("bag", "updatelocal", null);
                    ModelProxy.change("qianghua", "updatearm", null);
                    ModelProxy.change("jianding", "updatearm", null);
                    _loc_4 = ModelProxy.getValue("localCache", "option");
                    if (_loc_4 && _loc_4.offbasesound != 1)
                    {
                        if (_loc_5.pos == 1)
                        {
                            ModelProxy.change("main", "playsound", SoundType.BTN_ARMON2);
                        }
                        else
                        {
                            ModelProxy.change("main", "playsound", SoundType.BTN_ARMON1);
                        }
                    }
                    ModelProxy.change("role", "showShenZhuangBuffer", null);
                    break;
                }
                case CMDRole.TakeOff:
                {
                    _loc_3 = ModelProxy.getValue("data", "arms");
                    _loc_3[param1.getParam()] = null;
                    ModelProxy.change("role", "offarm", param1.getParam());
                    ModelProxy.change("wing", "unloadEquip", param1.getParam());
                    ModelProxy.change("bag", "updatelocal", null);
                    ModelProxy.change("qianghua", "updatearm", null);
                    ModelProxy.change("jianding", "updatearm", null);
                    _loc_6 = ModelProxy.getValue("localCache", "option");
                    if (_loc_6 && _loc_6.offbasesound != 1)
                    {
                        if (param1.getParam() == 1)
                        {
                            ModelProxy.change("main", "playsound", SoundType.BTN_ARMON2);
                        }
                        else
                        {
                            ModelProxy.change("main", "playsound", SoundType.BTN_ARMON1);
                        }
                    }
                    ModelProxy.change("role", "showShenZhuangBuffer", null);
                    break;
                }
                case CMDRole.UpdateRole:
                {
                    _loc_7 = param1.getParam();
                    ModelProxy.change("role", "updaterole", _loc_7);
                    ModelProxy.change("mainui", "updaterole", _loc_7);
                    break;
                }
                case CMDRole.Error:
                {
                    ModelProxy.change("movetips", "error", param1.getParam());
                    break;
                }
                case CMDRole.Durable:
                {
                    _loc_8 = param1.getParam();
                    if (_loc_8 == null)
                    {
                        break;
                    }
                    for (_loc_9 in _loc_8)
                    {
                        
                        if (_loc_8[_loc_9] <= 10)
                        {
                            ModelProxy.change("leftTishi", "naijiu", null);
                            _loc_10 = getTimer();
                            if (VipCheck.hasfunc(23) != 0)
                            {
                                _loc_4 = ModelProxy.getValue("data", "option");
                                if (_loc_4.autofix == 1)
                                {
                                    if (_loc_10 > this._lastfix + 10000)
                                    {
                                        this._lastfix = _loc_10;
                                        PluginManager.instance.sendToServer("shop", CMDShop.XiuAll, 1);
                                    }
                                }
                            }
                            break;
                        }
                    }
                    ModelProxy.change("role", "durables", param1.getParam());
                    break;
                }
                case CMDRole.SuperGather:
                {
                    ModelProxy.change("data", "user.gather", param1.getParam());
                    ModelProxy.setAction("gather", "update");
                    break;
                }
                case CMDRole.LookOther:
                {
                    ModelProxy.change("plugin", "change", {target:"roletwo", data:param1.getParam()});
                    break;
                }
                case CMDRole.GetAttribute:
                {
                    ModelProxy.change("zhuan", "getatt", param1.getParam());
                    break;
                }
                case 101:
                {
                    ModelProxy.change("data", "user", param1.getParam());
                    break;
                }
                case CMDRole.AddJm:
                {
                    ModelProxy.change("data", "roledata.jingmai", param1.getParam());
                    ModelProxy.change("role", "showjm", null);
                    break;
                }
                case CMDRole.SetTitle:
                {
                    break;
                }
                case CMDRole.HideTitle:
                {
                    break;
                }
                case CMDRole.UpdateTitle:
                {
                    break;
                }
                case CMDRole.UpdatePow:
                {
                    ModelProxy.change("role", "updatePowArr", param1.getParam());
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_2:int = 0;
            var _loc_4:Input = null;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:Object = null;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            var _loc_12:int = 0;
            var _loc_3:* = new Object();
            _loc_4 = new Input(null);
            var _loc_5:* = param1.getBody();
            param1.getBody().position = 0;
            _loc_4.setBytes(_loc_5);
            switch(param1.getCmd())
            {
                case CMDRole.Init:
                {
                    _loc_7 = _loc_4.readShort();
                    _loc_3.titleList = new Array();
                    _loc_10 = 0;
                    while (_loc_10 < _loc_7)
                    {
                        
                        _loc_11 = _loc_4.readByte();
                        if (_loc_11 != 0)
                        {
                            _loc_3.titleList[_loc_10] = new Object();
                            _loc_3.titleList[_loc_10].titleId = _loc_4.readVarInt(false);
                            _loc_3.titleList[_loc_10].endTime = _loc_4.readVarInt(false);
                        }
                        _loc_10++;
                    }
                    ModelProxy.change("data", "titles", _loc_3.titleList);
                    ModelProxy.change("role", "init", _loc_3.titleList);
                    if (_loc_7 > 0)
                    {
                        ModelProxy.change("bufferView", "addBindBuffer", "chenhao");
                    }
                    ModelProxy.change("role", "showShenZhuangBuffer", null);
                    break;
                }
                case CMDRole.UpdateTitle:
                {
                    _loc_8 = _loc_4.readByte();
                    if (_loc_8 != 0)
                    {
                        _loc_3.title = new Object();
                        _loc_3.title.titleId = _loc_4.readVarInt(false);
                        _loc_3.title.endTime = _loc_4.readVarInt(false);
                    }
                    DialogMgr.instance.open(AppDialog.ADD_TITLE, _loc_3.title.titleId);
                    _loc_6 = ModelProxy.getValue("data", "titles");
                    if (_loc_6)
                    {
                        _loc_6.push(_loc_3.title);
                    }
                    else
                    {
                        ModelProxy.change("data", "titles", [_loc_3.title]);
                    }
                    ModelProxy.change("bufferView", "addBindBuffer", "chenhao");
                    ModelProxy.change("role", "updatetitles", null);
                    break;
                }
                case CMDRole.RemoveTitle:
                {
                    _loc_3.titleId = _loc_4.readVarInt(false);
                    _loc_6 = ModelProxy.getValue("data", "titles");
                    if (_loc_6)
                    {
                        _loc_12 = 0;
                        while (_loc_12 < _loc_6.length)
                        {
                            
                            if (_loc_6[_loc_12])
                            {
                                if (_loc_6[_loc_12].titleId == _loc_3.titleId)
                                {
                                    delete _loc_6[_loc_12];
                                    break;
                                }
                            }
                            _loc_12++;
                        }
                        if (_loc_6.length == 0)
                        {
                            _loc_6 = null;
                        }
                    }
                    ModelProxy.change("role", "updatetitles", null);
                    DialogMgr.instance.open(AppDialog.ADD_TITLE, {p:_loc_3.titleId, type:1});
                    if (_loc_6 == null || _loc_6.length == 0)
                    {
                        ModelProxy.change("bufferView", "removeBindBuffer", "chenhao");
                    }
                    break;
                }
                case CMDRole.SetTitle:
                {
                    _loc_3.titleId = _loc_4.readVarInt(false);
                    ModelProxy.change("data", "user.title", _loc_3.titleId > 0 ? (_loc_3.titleId) : (null));
                    ModelProxy.change("role", "updateTitle", _loc_3.titleId > 0 ? (_loc_3.titleId) : (null));
                    break;
                }
                case CMDRole.HideTitle:
                {
                    break;
                }
                case CMDRole.YiJianHuanZhuangRES:
                {
                    _loc_3.level = _loc_4.readVarInt(false);
                    ModelProxy.change("appdialog", "open", {dialogID:AppDialog.YJHZ, data:_loc_3});
                    break;
                }
                case CMDRole.ReturnNeiGongInfo:
                {
                    _loc_2 = _loc_4.readByte();
                    if (_loc_2 != 0)
                    {
                        _loc_3.innerPower = new Object();
                        _loc_3.innerPower.level = _loc_4.readVarInt(false);
                        _loc_3.innerPower.exp = _loc_4.readLong().toNumber();
                    }
                    ModelProxy.change("role", "getNeiGongInfo", _loc_3);
                    ModelProxy.change("data", "neiGongCount", _loc_3.innerPower);
                    ModelProxy.change("mainview", "showNeiGongCount", _loc_3.innerPower);
                    break;
                }
                case CMDRole.ReturnNeiGongUp:
                {
                    _loc_2 = _loc_4.readByte();
                    if (_loc_2 != 0)
                    {
                        _loc_3.innerPower = new Object();
                        _loc_3.innerPower.level = _loc_4.readVarInt(false);
                        _loc_3.innerPower.exp = _loc_4.readLong().toNumber();
                    }
                    ModelProxy.change("data", "neiGongCount", _loc_3.innerPower);
                    ModelProxy.change("role", "updateNeiGongCount", _loc_3);
                    ModelProxy.change("mainview", "showNeiGongCount", _loc_3.innerPower);
                    break;
                }
                case CMDRole.updateNeiGongExp:
                {
                    _loc_3.addExp = _loc_4.readVarInt(false);
                    ModelProxy.change("mainui", "logview", "获得 " + _loc_3.addExp + "内功经验");
                    _loc_9 = ModelProxy.getValue("data", "neiGongCount");
                    if (_loc_9)
                    {
                        _loc_9.exp = _loc_3.addExp + _loc_9.exp;
                    }
                    ModelProxy.change("role", "updateNeiGongExp", _loc_3.addExp);
                    ModelProxy.change("mainview", "showNeiGongAddCount", _loc_3.addExp);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
